<include file="Common/common" />
<?php $statusArr = array('0'=>'等待上传凭证','1'=>'等待审核','2'=>'完成'); ?>

<body>
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this">订单列表</li>
					<li>发布</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<div style="overflow-x: auto;">
							<table class="layui-table" id="feedback-list">
								<thead>
										<tr>
											<th>编号</th>
											<th>积分数量</th>
											<th>折扣</th>
											<th>需要支付USDT数量/钱包地址</th>
											<th>购买人账户/手机号</th>
											<th>状态</th>
											<th>订单时间</th>
											<th>退回留言</th>
											<th>操作</th>
										</tr> 
									</thead>
									<tbody>
										<foreach name="ordercenterList" item="vo">
											<tr>
												<td>{$vo['id']}</td>
												<td>{$vo['num']}</td>
												<td>{$vo['discount']}</td>
												<td>{$vo['num_usdt']}/{$vo['wallet_address']}</td>
												<td>{$vo['account']}/{$vo['phone']}</td>
												<td>{$statusArr[$vo['status']]}</td>
												<td><?php if(!empty($vo['paytime'])){echo date('Y-m-d H:i:s',$vo['paytime']); } ?></td>
												<td>{$vo['remark']}</td>
												<th>
													<div class="layui-btn-group">
														<if condition="$vo['status'] elt 1 ">
															
															<button class="layui-btn layui-btn-sm" onclick="func_show(this,{$vo['id']})" >查看凭证</button>
														 	<button class="layui-btn layui-btn-sm" onclick="func_finish(this,{$vo['id']})">确认</button>
														 	
														 	
													 	</if>
														<if condition="$vo['status'] eq 1 ">
															<button class="layui-btn layui-btn-sm" onclick="func_back(this,{$vo['id']})">退回</button>
														</if>
												 	</div>
												</th>
											</tr>
										</foreach>
									</tbody>
							</table>
						</div>
						<div class="green-black">{$page}</div>
					</div>

					<!-- 发布订单 -->
					<div class="layui-tab-item">
						<form class="layui-form" action="">
							<div class="layui-form-item">
								<label class="layui-form-label">积分数量</label>
								<div class="layui-input-block">
									<input type="number" name="num" min="0" lay-verify="number|required" autocomplete="off"  class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">折扣</label>
								<div class="layui-input-block">
									<input type="text" name="discount"  lay-verify="required" autocomplete="off"  class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">支付USDT</label>
								<div class="layui-input-block">
									<input type="number" name="num_usdt" min="0" lay-verify="number|required" autocomplete="off"  class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">钱包地址</label>
								<div class="layui-input-block">
									<input type="text" name="wallet_address"  lay-verify="required" autocomplete="off" placeholder="aaa,bbb,ccc,ddd这里使用英文逗号"  class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">手机号</label>
								<div class="layui-input-block">
									<input type="text" name="phone" placeholder="18011111111,18022222222,18033333333,18044444444这里使用英文逗号" lay-verify="required" autocomplete="off"  class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="layui-btn" lay-submit="" lay-filter="btn-center">立即发布</button>
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
							</div>

						</form>

						<div style="overflow-x: auto;">
							<table class="layui-table" id="feedback-list">
								<thead>
										<tr>
											<th>积分数量</th>
											<th>折扣</th>
											<th>需要支付USDT数量</th>
											<th>钱包地址</th>
											<th>手机号</th>
											<th>操作</th>
										</tr> 
									</thead>
									<tbody>
										<foreach name="sellcenterList" item="vo">
											<tr>
												<td>{$vo['num']}</td>
												<td>{$vo['discount']}</td>
												<td>{$vo['num_usdt']}</td>
												<td>{$vo['wallet_address']}</td>
												<td>{$vo['phone']}</td>
												<td>
													<button class="layui-btn" onclick="func_delete(this,{$vo['id']})" >删除</button>
												</td>
											</tr>
										</foreach>
									</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
			
			
		</div>
	</div>
</body>
<script type="text/javascript">

	layui.use(['form'], function(){
		var form = layui.form;
		form.render();

		// 发布中心积分
		form.on('submit(btn-center)',function (data) {
			layer.confirm('确定发布？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('/admin.php/Order/ctrl_addSellcenter')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
			               	setTimeout(function(){location.reload();}, 1000);
		               	}
		               	layer.msg(rtJson.msg);
		            }
		        });
			});
			return false;
		});
	});


	// 退回
	function func_back(obj,id){
		layer.open({
			type: 2,
			title: '退回留言',
			shadeClose: true,
			closeBtn: 0,
			shade: 0.8,
			scrollbar: false,
			area: ['60%', '60%'],
			content: "/admin.php/Order/back?id="+id, //iframe的url
			btn: ['确定退回','取消'],
		  	yes: function(index, layero){
		  		var content = layero.find("iframe")[0].contentWindow.$("#content").val();
		    	
		    	if (content.trim() == '') {
		    		layer.msg('留言不能为空');
		    		return false;
		    	}
				layer.confirm('确定退回？',{offset:'none'},function(index){

	            	$.ajax({
			            type: "post",
			            url: "{:U('/admin.php/Order/ctrl_backcenter')}",
			            data: {id:id,content:content},
			            dataType: "json",
			            success: function(rtJson){
			            	if (rtJson.code == 1) {
			            		layer.msg(rtJson.msg);
				               	setTimeout(function(){location.reload();}, 1000);
			               	}else{
			               		layer.msg(rtJson.msg);
			               	}
			            }
			        });
			    });
		  	},
		  	btn2: function(index, layero){
			    
			    layer.close(index);
  			}
		});
	}

	// 删除
	function func_delete(obj,id){
		layer.confirm('确定删除？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('/admin.php/Order/ctrl_deleteCenter')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
	            		$(obj).parent().parent().remove();
	            	}
	            	layer.msg(rtJson.msg);
            		
	            }
	        });
		});
	}

	// 完成
	function func_finish(obj,id){
		layer.confirm('查看凭证无误，确认通过？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('/admin.php/Order/ctrl_buyCenterFinish')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
	            		setTimeout(function(){location.reload();}, 1000);
	            	}
	            	layer.msg(rtJson.msg);
            		
	            }
	        });
		});
	}


	// 查看打款凭证
	function func_show(obj,id){
		
		layer.open({
			type: 2,
			title: '编号：'+id,
			shadeClose: true,
			shade: 0.8,
			scrollbar: false,
			area: ['100%', '100%'],
			content: "/admin.php/Order/show?id="+id, //iframe的url
			
		});
	}
</script>
<include file="Common/footer" />